Conditions | 1 |
Paths | 6 |
Total Lines | 579 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | jQuery(function($) { |
||
2 | $('body').bind('wpinv_tax_recalculated', function(e, data) { |
||
3 | var el = $('#wpinv_adddress_confirm'); |
||
4 | el.hide(); |
||
5 | if (WPInv_VAT_Vars.ApplyVATRules) { |
||
|
|||
6 | var eu_state = wpinv_is_eu_state(data.post.country); |
||
7 | var non_eu = !eu_state && !wpinv_is_eu_state(el.attr('value')); |
||
8 | if (!non_eu && $('#wpinv_vat_number').val().trim().length === 0 && data.post.country !== el.attr('value')) { |
||
9 | el.show(); |
||
10 | } |
||
11 | } |
||
12 | }); |
||
13 | var WPInv_VAT_Config = { |
||
14 | init: function() { |
||
15 | this.taxes(this); |
||
16 | var me = this; |
||
17 | }, |
||
18 | checkVATNumber: function(el, err) { |
||
19 | try { |
||
20 | if (el) { |
||
21 | var valid = false; |
||
22 | var msg = ''; |
||
23 | var value = el.val(); |
||
24 | if (value.length > 0) { |
||
25 | if (checkVATNumber(value)) { |
||
26 | valid = true; |
||
27 | } else { |
||
28 | msg = WPInv_VAT_Vars.ErrInvalidVat; |
||
29 | } |
||
30 | } else { |
||
31 | msg = WPInv_VAT_Vars.EmptyVAT; |
||
32 | } |
||
33 | if (valid) { |
||
34 | return true; |
||
35 | } else if (err && msg) { |
||
36 | alert(msg); |
||
37 | } |
||
38 | return false; |
||
39 | } |
||
40 | return; |
||
41 | } catch (e) { |
||
42 | if (err) { |
||
43 | alert(WPInv_VAT_Vars.ErrValidateVAT + ": " + e.message); |
||
44 | } |
||
45 | return false; |
||
46 | } |
||
47 | }, |
||
48 | taxes: function(config) { |
||
49 | var has_vat = $('#wpi_vat_info').is(':visible'); |
||
50 | var eu_states = WPInv_VAT_Vars.EUStates; |
||
51 | $('body').bind('wpinv_tax_recalculated', function(e, data) { |
||
52 | $('.wpinv_errors').html('').hide(); |
||
53 | if (data.post.country === 'UK') { |
||
54 | data.post.country = 'GB'; |
||
55 | } |
||
56 | var eu_state = wpinv_is_eu_state(data.post.country); |
||
57 | if (eu_state && WPInv_VAT_Vars.disableVATSameCountry && wpinv_is_base_country(data.post.country)) { |
||
58 | eu_state = false; |
||
59 | } |
||
60 | if (eu_state && !WPInv_VAT_Vars.HideVatFields) { |
||
61 | $('#wpi_vat_info').show(); |
||
62 | $('#wpi_vat_info').parent('.wpi-vat-details').show(); |
||
63 | } else { |
||
64 | $('#wpi_vat_info').hide(); |
||
65 | } |
||
66 | if (has_vat == eu_state) { |
||
67 | if (eu_state) { |
||
68 | config.reset(config, $('#wpinv_vat_reset'), false); |
||
69 | } |
||
70 | return; |
||
71 | } |
||
72 | has_vat = eu_state; |
||
73 | wpinv_recalculate_taxes(); |
||
74 | }); |
||
75 | $('#wpi_add_eu_states').on('click', function() { |
||
76 | var rate = $('#wpinv_settings_rates_eu_fallback_rate').val(); |
||
77 | if (rate === null || rate === '') { |
||
78 | if (!confirm(WPInv_VAT_Vars.NoRateSet)) return; |
||
79 | } |
||
80 | $('#wpi_remove_eu_states').trigger('click'); |
||
81 | var row = $('#wpinv_tax_rates tbody tr:last'); |
||
82 | var clone = row.clone(); |
||
83 | var body = row.parent(); |
||
84 | var count = $('#wpinv_tax_rates tbody tr').length; |
||
85 | $.each(eu_states, function(i, state) { |
||
86 | row = clone.clone(); |
||
87 | row.find('td input').val(''); |
||
88 | row.find('input, select').each(function() { |
||
89 | var name = $(this).attr('name'); |
||
90 | name = name.replace(/\[(\d+)\]/, '[' + parseInt(count) + ']'); |
||
91 | $(this).attr('name', name).attr('id', name); |
||
92 | }); |
||
93 | row.find('#tax_rates\\[' + count + '\\]\\[rate\\]').val(rate); |
||
94 | row.find('#tax_rates\\[' + count + '\\]\\[country\\]').val(state); |
||
95 | row.find('#tax_rates\\[' + count + '\\]\\[state\\]').replaceWith('<input type="text" class="regular-text" value="" id="tax_rates[' + count + '][state]" name="tax_rates[' + count + '][state]">'); |
||
96 | row.find('#tax_rates\\[' + count + '\\]\\[global\\]').prop('checked', true); |
||
97 | row.find('#tax_rates\\[' + count + '\\]\\[global\\]').val(1); |
||
98 | body.append(row); |
||
99 | count++; |
||
100 | }); |
||
101 | return false; |
||
102 | }); |
||
103 | $('#wpi_remove_eu_states').on('click', function() { |
||
104 | $('#wpinv_tax_rates select.wpinv-tax-country').each(function(i) { |
||
105 | if (jQuery(this).val() && wpinv_is_eu_state(jQuery(this).val())) { |
||
106 | if ($('#wpinv_tax_rates tbody tr').length === 1) { |
||
107 | $('#wpinv_tax_rates select').val(''); |
||
108 | $('#wpinv_tax_rates select').trigger('change'); |
||
109 | $('#wpinv_tax_rates input[type="text"]').val(''); |
||
110 | $('#wpinv_tax_rates input[type="number"]').val(''); |
||
111 | $('#wpinv_tax_rates input[type="checkbox"]').attr('checked', false); |
||
112 | } else { |
||
113 | jQuery(this).closest('tr').remove(); |
||
114 | } |
||
115 | } |
||
116 | }); |
||
117 | }); |
||
118 | jQuery('#wpi_vat_get_rates').on('click', function(e) { |
||
119 | e.preventDefault(); |
||
120 | var $this = $(this); |
||
121 | $this.blur(); |
||
122 | WPInv_VAT_Config.disableButtons(); |
||
123 | var $loading = $this.closest('span').find('.fa-refresh'); |
||
124 | $loading.show(); |
||
125 | var data = { |
||
126 | action: 'wpinv_update_vat_rates', |
||
127 | group: 'standard' |
||
128 | }; |
||
129 | jQuery.post(ajaxurl, data, function(response) { |
||
130 | try { |
||
131 | if (!response) { |
||
132 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.ErrRateResponse); |
||
133 | return; |
||
134 | } |
||
135 | var vat_rates_array = response; |
||
136 | if (vat_rates_array.success !== true) { |
||
137 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.GetRateRequestFailed + (vat_rates_array.error ? vat_rates_array.error : 'reason unknown')); |
||
138 | return; |
||
139 | } |
||
140 | if (!vat_rates_array.data) { |
||
141 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.NoRateInformationInResponse); |
||
142 | return; |
||
143 | } |
||
144 | var vat_rates = vat_rates_array.data; |
||
145 | var countries = jQuery('#wpinv_tax_rates select.wpinv-tax-country'); |
||
146 | countries.each(function(i, country_td) { |
||
147 | var country_el = jQuery(country_td); |
||
148 | var code = country_el.val(); |
||
149 | if (!vat_rates.rates[code]) { |
||
150 | return; |
||
151 | } |
||
152 | var rate_el = country_el.closest('tr').find('.wpinv_tax_rate input'); |
||
153 | var rate_class = country_el.closest('tr').find('.wpinv_tax_rate input'); |
||
154 | var rate = vat_rates.rates[code].standard; |
||
155 | rate_el.val(rate); |
||
156 | }); |
||
157 | $loading.hide(); |
||
158 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.RatesUpdated); |
||
159 | } catch (e) { |
||
160 | $loading.hide(); |
||
161 | WPInv_VAT_Config.showError(e.message); |
||
162 | } |
||
163 | }) |
||
164 | .fail(function(jqXHR, textStatus, errorThrown) { |
||
165 | $loading.hide(); |
||
166 | $this.removeAttr('disabled', 'disabled'); |
||
167 | }); |
||
168 | }); |
||
169 | jQuery('#wpi_vat_get_rates_group').on('click', function(e) { |
||
170 | e.preventDefault(); |
||
171 | var $this = $(this); |
||
172 | $this.blur(); |
||
173 | WPInv_VAT_Config.disableButtons(); |
||
174 | var $loading = $this.closest('span').find('.fa-refresh'); |
||
175 | $loading.show(); |
||
176 | var data = { |
||
177 | action: 'wpinv_update_vat_rates' |
||
178 | }; |
||
179 | jQuery.post(ajaxurl, data, function(response) { |
||
180 | try { |
||
181 | if (!response) { |
||
182 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.ErrRateResponse); |
||
183 | return; |
||
184 | } |
||
185 | var vat_rates_array = response; |
||
186 | if (vat_rates_array.success !== true) { |
||
187 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.GetRateRequestFailed + (vat_rates_array.error ? vat_rates_array.error : 'reason unknown')); |
||
188 | return; |
||
189 | } |
||
190 | if (!vat_rates_array.data) { |
||
191 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.NoRateInformationInResponse); |
||
192 | return; |
||
193 | } |
||
194 | var vat_rates = vat_rates_array.data; |
||
195 | jQuery.each(vat_rates.rates, function(sCode, oRate) { |
||
196 | if (sCode) { |
||
197 | var sGroup = jQuery('.wpinv_vat_group select[name="vat_rates[' + sCode + '][group]"]').val(); |
||
198 | if (sGroup && typeof oRate[sGroup] !== 'undefined') { |
||
199 | jQuery('.wpinv_vat_rate input[name="vat_rates[' + sCode + '][rate]"]').val(parseFloat(oRate[sGroup])); |
||
200 | } |
||
201 | } |
||
202 | }); |
||
203 | $loading.hide(); |
||
204 | WPInv_VAT_Config.showError(WPInv_VAT_Vars.RatesUpdated); |
||
205 | } catch (e) { |
||
206 | $loading.hide(); |
||
207 | WPInv_VAT_Config.showError(e.message); |
||
208 | } |
||
209 | }) |
||
210 | .fail(function(jqXHR, textStatus, errorThrown) { |
||
211 | $loading.hide(); |
||
212 | $this.removeAttr('disabled', 'disabled'); |
||
213 | }); |
||
214 | }); |
||
215 | $('#wpi_vat_rate_add').on('click', function() { |
||
216 | var $n = $('#wpinv_settings\\[vat_rate_name\\]'); |
||
217 | var $d = $('#wpinv_settings\\[vat_rate_desc\\]'); |
||
218 | var $r = $('.wpi-vat-rate-actions .fa-refresh'); |
||
219 | var n = $.trim($n.val()); |
||
220 | var d = $.trim($d.val()); |
||
221 | if (!n) { |
||
222 | $n.focus(); |
||
223 | return false; |
||
224 | } |
||
225 | var me = $(this); |
||
226 | me.attr('disabled', 'disabled'); |
||
227 | $r.show(); |
||
228 | var data = { |
||
229 | action: 'wpinv_add_vat_class', |
||
230 | name: n, |
||
231 | desc: d |
||
232 | }; |
||
233 | $.post(ajaxurl, data, function(json) { |
||
234 | var error = ''; |
||
235 | var message = ''; |
||
236 | if (json && typeof json == 'object') { |
||
237 | if (json.success === true) { |
||
238 | $r.removeClass('fa-refresh fa-spin').addClass('fa-check-circle orange'); |
||
239 | window.location = json.redirect; |
||
240 | return; |
||
241 | } else { |
||
242 | error = json.error ? json.error : ''; |
||
243 | } |
||
244 | } |
||
245 | me.removeAttr('disabled'); |
||
246 | $r.hide(); |
||
247 | if (error) { |
||
248 | alert(error); |
||
249 | } |
||
250 | return; |
||
251 | }) |
||
252 | .fail(function() { |
||
253 | me.removeAttr('disabled'); |
||
254 | $r.hide(); |
||
255 | }); |
||
256 | }); |
||
257 | $('#wpi_vat_rate_delete').on('click', function() { |
||
258 | var $c = $('#wpinv_settings\\[vat_rates_class\\]'); |
||
259 | var $r = $('.wpi-vat-rate-actions .fa-refresh'); |
||
260 | var c = $.trim($c.val()); |
||
261 | if (!confirm(WPInv_VAT_Vars.ConfirmDeleteClass)) { |
||
262 | return; |
||
263 | } |
||
264 | var me = $(this); |
||
265 | me.attr('disabled', 'disabled'); |
||
266 | $r.show(); |
||
267 | var data = { |
||
268 | action: 'wpinv_delete_vat_class', |
||
269 | class: c, |
||
270 | }; |
||
271 | $.post(ajaxurl, data, function(json) { |
||
272 | var error = ''; |
||
273 | var message = ''; |
||
274 | if (json && typeof json == 'object') { |
||
275 | if (json.success === true) { |
||
276 | $r.removeClass('fa-refresh fa-spin').addClass('fa-check-circle orange'); |
||
277 | window.location = json.redirect; |
||
278 | return; |
||
279 | } else { |
||
280 | error = json.error ? json.error : ''; |
||
281 | } |
||
282 | } |
||
283 | me.removeAttr('disabled'); |
||
284 | $r.hide(); |
||
285 | if (error) { |
||
286 | alert(error); |
||
287 | } |
||
288 | return; |
||
289 | }) |
||
290 | .fail(function() { |
||
291 | me.removeAttr('disabled'); |
||
292 | $r.hide(); |
||
293 | }); |
||
294 | }); |
||
295 | jQuery('#wpi_geoip2').on('click', function(e) { |
||
296 | e.preventDefault(); |
||
297 | var el = $(this); |
||
298 | var action = el.attr('action'); |
||
299 | el.blur().attr('disabled', 'disabled'); |
||
300 | el.after(' <i id="wpi-downloading" class="fa fa-refresh fa-spin"></i>'); |
||
301 | $('#wpi-downloading').show(); |
||
302 | var data = { |
||
303 | action: 'wpinv_geoip2', |
||
304 | }; |
||
305 | jQuery.post(ajaxurl, data, |
||
306 | function(response) { |
||
307 | var msg = ''; |
||
308 | var reload = false; |
||
309 | try { |
||
310 | if (response) { |
||
311 | reload = action == 'download' ? true : false; |
||
312 | msg = response + (action == 'download' ? ' ' + WPInv_VAT_Vars.PageRefresh : ''); |
||
313 | } else { |
||
314 | msg = WPInv_VAT_Vars.ErrResponse; |
||
315 | } |
||
316 | } catch (e) { |
||
317 | msg = e.message; |
||
318 | } |
||
319 | WPInv_VAT_Config.showGeoIP2Error(msg, el, reload); |
||
320 | }).fail(function(jqXHR, textStatus, errorThrown) { |
||
321 | WPInv_VAT_Config.showGeoIP2Error("Status: " + textStatus, el); |
||
322 | }) |
||
323 | }); |
||
324 | $('#wpinv_vat_reset').on('click', function(e) { |
||
325 | e.preventDefault(); |
||
326 | WPInv_VAT_Config.reset(WPInv_VAT_Config, $(this), true); |
||
327 | }); |
||
328 | if (WPInv_VAT_Vars.isFront) { |
||
329 | var elErr = $('.wpi-cart-field-actions .wpi-vat-box-error'); |
||
330 | var elInfo = $('.wpi-cart-field-actions .wpi-vat-box-info'); |
||
331 | $('#wpinv_vat_validate').on('click', function() { |
||
332 | elErr.hide(); |
||
333 | elInfo.hide(); |
||
334 | var companyEl = $('#wpinv_checkout_form #wpinv_company'); |
||
335 | var company = companyEl.val(); |
||
336 | var numberEl = $('#wpinv_checkout_form #wpinv_vat_number'); |
||
337 | var vat_number = numberEl.val(); |
||
338 | if ((company && (company.length > 0)) || (vat_number && (vat_number.length > 0))) { |
||
339 | if (!(company && (company.length > 0))) { |
||
340 | WPInv_VAT_Config.displayMessage(WPInv_VAT_Vars.EmptyCompany, 'error'); |
||
341 | return false; |
||
342 | } |
||
343 | if (!(vat_number && (vat_number.length > 0))) { |
||
344 | WPInv_VAT_Config.displayMessage(WPInv_VAT_Vars.EmptyVAT, 'error'); |
||
345 | return false; |
||
346 | } |
||
347 | } |
||
348 | if (!WPInv_VAT_Vars.disableVATSimpleCheck && (vat_number && (vat_number.length > 0)) && !WPInv_VAT_Config.checkVATNumber(numberEl, false)) { |
||
349 | WPInv_VAT_Config.displayMessage(WPInv_VAT_Vars.ErrValidateVAT, 'error'); |
||
350 | return false; |
||
351 | } |
||
352 | var number = numberEl.val(); |
||
353 | var nonce = $('input[name=_wpi_nonce]').val(); |
||
354 | var me = $(this); |
||
355 | me.attr('disabled', 'disabled'); |
||
356 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-0 wpinv-vat-stat-1').addClass('wpinv-vat-stat-2'); |
||
357 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatValidating); |
||
358 | var data = { |
||
359 | action: 'wpinv_vat_validate', |
||
360 | company: company, |
||
361 | number: number, |
||
362 | country: $('[name=wpinv_country]').val(), |
||
363 | source: 'checkout', |
||
364 | _wpi_nonce: nonce |
||
365 | }; |
||
366 | $.post(ajaxurl, data, function(json) { |
||
367 | var validated = false; |
||
368 | var error = ''; |
||
369 | var message = ''; |
||
370 | if (json && typeof json == 'object') { |
||
371 | if (json.success === true) { |
||
372 | validated = true; |
||
373 | message = json.message ? json.message : ''; |
||
374 | } else { |
||
375 | error = json.error ? json.error : json.message; |
||
376 | } |
||
377 | } |
||
378 | me.removeAttr('disabled'); |
||
379 | if (validated) { |
||
380 | if (number.length === 0) {} else { |
||
381 | me.hide(); |
||
382 | $('#wpinv_vat_reset').show(); |
||
383 | } |
||
384 | $('.wpinv-vat-stat font').html(message ? message : WPInv_VAT_Vars.VatValidated); |
||
385 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-1'); |
||
386 | } else { |
||
387 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatNotValidated); |
||
388 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-0'); |
||
389 | } |
||
390 | if (number.length > 0 || $('#wpinv_country').val() === $('#wpinv_adddress_confirm').attr('value')) { |
||
391 | $('#wpinv_adddress_confirm').hide(); |
||
392 | } else { |
||
393 | $('#wpinv_adddress_confirm').show(); |
||
394 | } |
||
395 | if (error) { |
||
396 | config.displayMessage(error + '<br>' + WPInv_VAT_Vars.TotalsRefreshed, 'error'); |
||
397 | } else { |
||
398 | config.displayMessage(WPInv_VAT_Vars.TotalsRefreshed, 'info'); |
||
399 | } |
||
400 | wpinv_recalculate_taxes(); |
||
401 | return; |
||
402 | }) |
||
403 | .fail(function() { |
||
404 | me.removeAttr('disabled'); |
||
405 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatNotValidated); |
||
406 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-0'); |
||
407 | WPInv_VAT_Config.displayMessage(WPInv_VAT_Vars.ErrValidateVAT, 'error'); |
||
408 | }); |
||
409 | }); |
||
410 | } else { |
||
411 | $('#wpinv_vat_validate').on('click', function() { |
||
412 | var companyEl = $('#wpinv_settings\\[vat_company_name\\]'); |
||
413 | var company = companyEl.val(); |
||
414 | if (company.length == 0) { |
||
415 | alert(WPInv_VAT_Vars.EmptyCompany); |
||
416 | return false; |
||
417 | } |
||
418 | var vatEl = $('#wpinv_settings\\[vat_number\\]'); |
||
419 | var number = vatEl.val(); |
||
420 | if (!WPInv_VAT_Vars.disableVATSimpleCheck && !WPInv_VAT_Config.checkVATNumber(vatEl, true)) { |
||
421 | return false; |
||
422 | } |
||
423 | var nonce = $('input[name=_wpi_nonce]').val(); |
||
424 | var me = $(this); |
||
425 | me.attr('disabled', 'disabled'); |
||
426 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-0 wpinv-vat-stat-1').addClass('wpinv-vat-stat-2'); |
||
427 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatValidating); |
||
428 | var data = { |
||
429 | action: 'wpinv_vat_validate', |
||
430 | company: company, |
||
431 | number: number, |
||
432 | _wpi_nonce: nonce, |
||
433 | source: 'admin' |
||
434 | }; |
||
435 | $.post(ajaxurl, data, function(json) { |
||
436 | var validated = false; |
||
437 | var error = ''; |
||
438 | var message = ''; |
||
439 | if (json && typeof json == 'object') { |
||
440 | if (json.success === true) { |
||
441 | validated = true; |
||
442 | message = json.message ? json.message : ''; |
||
443 | } else { |
||
444 | error = json.message ? json.message : json.error; |
||
445 | } |
||
446 | } |
||
447 | if (validated) { |
||
448 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatValidated); |
||
449 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-1'); |
||
450 | } else { |
||
451 | me.removeAttr('disabled'); |
||
452 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatNotValidated); |
||
453 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-0'); |
||
454 | if (error) { |
||
455 | alert(error); |
||
456 | } |
||
457 | } |
||
458 | return; |
||
459 | }) |
||
460 | .fail(function() { |
||
461 | me.removeAttr('disabled'); |
||
462 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatNotValidated); |
||
463 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-0'); |
||
464 | alert(WPInv_VAT_Vars.ErrValidateVAT); |
||
465 | }); |
||
466 | }); |
||
467 | } |
||
468 | }, |
||
469 | clearBox: function() { |
||
470 | var texts = $('.wpi-vat-box #text'); |
||
471 | texts.html(''); |
||
472 | var boxes = texts.parents(".wpi-vat-box") |
||
473 | boxes.fadeOut('fast'); |
||
474 | }, |
||
475 | reset: function(config, me, updateTaxes) { |
||
476 | var tax = parseFloat($('#wpinv_checkout_form .wpinv_cart_tax_amount').attr('data-tax')); |
||
477 | var total = parseFloat($('#wpinv_checkout_form .wpinv_cart_amount').attr('data-total')); |
||
478 | var wpiCCaddressEl = $('#wpinv-fields .wpi-billing'); |
||
479 | var countryEl = wpiCCaddressEl.find('#wpinv_country').val(); |
||
480 | if (total === "0") { |
||
481 | $('#wpi_vat_info').hide(); |
||
482 | return; |
||
483 | } |
||
484 | if (tax !== "0" && countryEl === undefined) { |
||
485 | window.location.reload() |
||
486 | } |
||
487 | if (!WPInv_VAT_Vars.HideVatFields) { |
||
488 | $('#wpi_vat_info').parent('.wpi-vat-details').show(); |
||
489 | $('#wpi_vat_info').show(); |
||
490 | } |
||
491 | if (!updateTaxes) { |
||
492 | return; |
||
493 | } |
||
494 | var numberEl = $('#wpinv_vat_number'); |
||
495 | var number = numberEl.val(); |
||
496 | if (number.length === 0 && $('.wpinv-vat-stat').hasClass('wpinv-vat-stat-1')) { |
||
497 | return; |
||
498 | } |
||
499 | var nonce = $('input[name=_wpi_nonce]').val(); |
||
500 | me.attr('disabled', 'disabled'); |
||
501 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-0 wpinv-vat-stat-1').addClass('wpinv-vat-stat-2'); |
||
502 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatReseting); |
||
503 | var validateButton = $('#wpinv_vat_validate'); |
||
504 | validateButton.hide(); |
||
505 | var data = { |
||
506 | action: 'wpinv_vat_reset', |
||
507 | _wpi_nonce: nonce, |
||
508 | source: 'checkout' |
||
509 | }; |
||
510 | $.post(ajaxurl, data, function(response) { |
||
511 | var json = response; |
||
512 | $('#wpinv_company').val(""); |
||
513 | $('#wpinv_vat_number').val(""); |
||
514 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatNotValidated); |
||
515 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-0'); |
||
516 | validateButton.show(); |
||
517 | me.removeAttr('disabled'); |
||
518 | me.hide(); |
||
519 | if (json.success) { |
||
520 | $('#wpinv_company').val(json.data.company); // TODO |
||
521 | $('#wpinv_vat_number').val(json.data.number); // TODO |
||
522 | if (updateTaxes) { |
||
523 | wpinv_recalculate_taxes(); |
||
524 | } |
||
525 | return; |
||
526 | } |
||
527 | config.displayMessage(json === undefined || json.message === undefined ? WPInv_VAT_Vars.ErrInvalidResponse : json.message, 'error'); |
||
528 | }) |
||
529 | .fail(function(jqXHR, textStatus, errorThrown) { |
||
530 | me.removeAttr('disabled'); |
||
531 | me.show(); |
||
532 | $('.wpinv-vat-stat font').html(WPInv_VAT_Vars.VatNotValidated); |
||
533 | $('.wpinv-vat-stat').removeClass('wpinv-vat-stat-2').addClass('wpinv-vat-stat-0'); |
||
534 | config.displayMessage(WPInv_VAT_Vars.ErrResetVAT + " (" + textStatus + " - " + errorThrown + ")", 'error'); |
||
535 | }) |
||
536 | }, |
||
537 | showGeoIP2Error: function(msg, el, reload) { |
||
538 | el.removeAttr('disabled'); |
||
539 | jQuery('#wpi-downloading').hide(); |
||
540 | jQuery('#wpinv-geoip2-errors').html(msg).show(); |
||
541 | setTimeout(function() { |
||
542 | if (reload) { |
||
543 | window.location.reload(); |
||
544 | } else { |
||
545 | jQuery('#wpinv-geoip2-errors').hide(); |
||
546 | } |
||
547 | }, 10000); |
||
548 | }, |
||
549 | showError: function(message) { |
||
550 | WPInv_VAT_Config.enableButtons(); |
||
551 | var errorEl = jQuery('#wpinv-rates-error-wrap'); |
||
552 | errorEl.html(message); |
||
553 | errorEl.css("display", "block"); |
||
554 | setTimeout(function() { |
||
555 | errorEl.hide(); |
||
556 | }, 10000); |
||
557 | }, |
||
558 | disableButtons: function() { |
||
559 | $('#wpi_vat_get_rates').attr('disabled', 'disabled'); |
||
560 | $('#wpi_add_eu_states').attr('disabled', 'disabled'); |
||
561 | $('#wpi_remove_eu_states').attr('disabled', 'disabled'); |
||
562 | $('#wpi_vat_get_rates_group').attr('disabled', 'disabled'); |
||
563 | }, |
||
564 | enableButtons: function() { |
||
565 | $('#wpi_vat_get_rates').removeAttr('disabled'); |
||
566 | $('#wpi_add_eu_states').removeAttr('disabled'); |
||
567 | $('#wpi_remove_eu_states').removeAttr('disabled'); |
||
568 | $('#wpi_vat_get_rates_group').removeAttr('disabled'); |
||
569 | }, |
||
570 | displayMessage: function(m, c) { |
||
571 | var box = $('.wpi-vat-box.wpi-vat-box-' + c + ' #text'); |
||
572 | if (box) { |
||
573 | box.html(m); |
||
574 | box.parent().show().slideDown().css("display", "inline-block"); |
||
575 | } |
||
576 | } |
||
577 | }; |
||
578 | WPInv_VAT_Config.init(); |
||
579 | }); |
||
580 | |||
638 | } |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.